package com.app.news;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.media.Image;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.news.bean.News;
import com.app.news.util.GetJsonNewsUtil;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;

import java.util.List;

public class ShowActivity extends AppCompatActivity {

    private ImageView imageView1;
    private TextView textView1;
    private TextView textView2;
    private TextView textView3;
    private String Image1;
    private String title;
    private String getAuthor_name;
    private String date;
    private TextView urlTv;
    private String url;
    private ImageView imageView2;
    private ImageView imageView3;
    private String Image2;
    private String Image3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show);
        initView();
        initData();
        initEvent();
    }
    private void initView(){
        imageView1 = findViewById(R.id.image_iv);
        imageView2 = findViewById(R.id.image2_iv);
        imageView3 = findViewById(R.id.image3_iv);
        textView1 = findViewById(R.id.title_tv);
        textView2 = findViewById(R.id.getAuthor_name_tv);
        textView3 = findViewById(R.id.data_tv);
        urlTv = findViewById(R.id.url_tv);
    }
    private void initData(){
        Intent intent =getIntent();
        Image1 = intent.getStringExtra("image1");
        Image2 = intent.getStringExtra("image2");
        Image3 = intent.getStringExtra("image3");
        title = intent.getStringExtra("title");
        getAuthor_name = intent.getStringExtra("getAuthor_name");
        date = intent.getStringExtra("date");
        url = intent.getStringExtra("url");
        imageView1.setImageURI(Uri.parse(Image1));
        imageView2.setImageURI(Uri.parse(Image2));
        imageView3.setImageURI(Uri.parse(Image3));
        textView1.setText(title);
        textView2.setText(getAuthor_name);
        textView3.setText(date);
        urlTv.setText(url);
        Picasso.with(getApplicationContext()).load(Uri.parse(Image2)).into(imageView1);
        Picasso.with(getApplicationContext()).load(Uri.parse(Image1)).into(imageView2);
        Picasso.with(getApplicationContext()).load(Uri.parse(Image3)).into(imageView3);
    }
    private void initEvent(){
        urlTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(Intent.ACTION_VIEW);
                Uri uri = Uri.parse(urlTv.getText().toString()+"");
                intent.setData(uri);
                startActivity(intent);
            }
        });
    }
}
